Skip to content

Conversation

nbdd0121
Copy link
Member

Fixes #78171

@rust-highfive
Copy link
Contributor

r? @petrochenkov

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 14, 2021
@petrochenkov
Copy link
Contributor

I'd never guess that const { ... } patterns use PatKind::Lit internally.
@bors r+

@bors
Copy link
Collaborator

bors commented Aug 14, 2021

📌 Commit 17d18e3822d5e5876fbf9d2ddd6d2b4a6783e117 has been approved by petrochenkov

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 14, 2021
@nbdd0121
Copy link
Member Author

Actually this approach doesn't catch const { foo() }..2 case. Might be better to save in_pat and set it to false when visiting a AnonConst and restore it after visiting.

@nbdd0121
Copy link
Member Author

Added a test case for using inline const in range pattern

@nbdd0121
Copy link
Member Author

I'd never guess that const { ... } patterns use PatKind::Lit internally.

It's surprising to me as well, but I guess that's probably the easiest way to implement it since it'll need to have a P<Expr> anyway.

@petrochenkov
Copy link
Contributor

Might be better to save in_pat and set it to false when visiting a AnonConst and restore it after visiting.

Yeah, it's a better approach, it should also fix cases like

const fn one() -> i32 {
    1
}

struct S<const C: i32>;

fn main() {
    match S::<1> {
        S::<{one()}> => {}
    }
}

Could you actually add this case too?
And merge all the cases into a single test file, no need to run rustc multiple times to test all of this.

@bors r-

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Aug 15, 2021
@nbdd0121
Copy link
Member Author

Added and merged

@petrochenkov
Copy link
Contributor

Thanks!
@bors r+

@bors
Copy link
Collaborator

bors commented Aug 15, 2021

📌 Commit e62ecdc has been approved by petrochenkov

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Aug 15, 2021
camsteffen added a commit to camsteffen/rust that referenced this pull request Aug 15, 2021
Fix dead code warning when inline const is used in pattern

Fixes rust-lang#78171
bors added a commit to rust-lang-ci/rust that referenced this pull request Aug 19, 2021
…laumeGomez

Rollup of 10 pull requests

Successful merges:

 - rust-lang#87818 (Fix anchors display in rustdoc)
 - rust-lang#87983 (Use more accurate spans when proposing adding lifetime to item)
 - rust-lang#88012 (Change WASI's `RawFd` from `u32` to `c_int` (`i32`).)
 - rust-lang#88031 (Make `BuildHasher` object safe)
 - rust-lang#88036 (Fix dead code warning when inline const is used in pattern)
 - rust-lang#88082 (Take into account jobs number for rustdoc GUI tests)
 - rust-lang#88109 (Fix environment variable getter docs)
 - rust-lang#88111 (Add background-color on clickable definitions in source code)
 - rust-lang#88129 (Fix dataflow graphviz bug, make dataflow graphviz modules public)
 - rust-lang#88136 (Move private_unused.rs test to impl-trait)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 016f691 into rust-lang:master Aug 19, 2021
@rustbot rustbot added this to the 1.56.0 milestone Aug 19, 2021
@nbdd0121 nbdd0121 deleted the const3 branch September 4, 2021 02:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

dead_code lint triggers even though function is used in const pattern
6 participants